import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Solution1222 {

    public List<List<Integer>> queensAttacktheKing(int[][] queens, int[] king) {
        int a,b;
        int[] dx=new int[]{-1,-1,-1,0,0,1,1,1};
        int[] dy=new int[]{-1,0,1,-1,1,-1,0,1};
        List<List<Integer>> ans=new ArrayList<>();
        for (int i=0;i<8;i++){
            a=king[0];
            b=king[1];
            while (true){
                a=a+dx[i];
                b=b+dy[i];
                if (a>=0 && a<8 && b>=0 && b<8){
                    boolean flag=false;
                    for (int[] queen : queens) {
                        if (queen[0]==a && queen[1]==b){
                            ans.add(Arrays.asList(a,b));
                            flag=true;
                            break;
                        }
                    }
                    if (flag){
                        break;
                    }
                }else {
                    break;
                }
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1222().queensAttacktheKing(new int[][]{{0,1},{1,0},{4,0},{0,4},{3,3},{2,4}},new int[]{0,0}));
    }
}
